extends EnemyBase

const BULLET_SPEED_DELTA = 700

@export var enemy_bullet_scene: PackedScene

func _ready() -> void:
	super()
	add_to_group("enemy_adv")
	hp = 4
	fire_timer.wait_time = randf_range(1, 2)
	fire_timer.start()


func _process(delta: float) -> void:
	super(delta)
	
func fire() -> void:
	# 发射3次子弹
	for i in range(3):
		# 发射子弹
		spawn_bullets()
		# 每次子弹发射之间间隔0.2秒
		await get_tree().create_timer(0.2).timeout

	
func animate_explosion() -> void:
	$AnimatedSprite2D.play("explosion")
	await $AnimatedSprite2D.animation_finished

func spawn_bullets() -> void:
	var enemy_bullet_left = enemy_bullet_scene.instantiate()
	enemy_bullet_left.position.x = position.x - 25
	enemy_bullet_left.position.y = position.y + 20
	enemy_bullet_left.speed = speed + BULLET_SPEED_DELTA
	
	var enemy_bullet_right = enemy_bullet_scene.instantiate()
	enemy_bullet_right.position.x = position.x + 25
	enemy_bullet_right.position.y = position.y + 20
	enemy_bullet_right.speed = speed + BULLET_SPEED_DELTA
	
	get_parent().add_child(enemy_bullet_left)
	get_parent().add_child(enemy_bullet_right)
